<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\JsonRpc;

use App\Repository\CommentRepository;
use Hyperf\RpcServer\Annotation\RpcService;
use App\JsonRpc\Interfaces\CommentServiceInterface;

/**
 * @RpcService(name="Orders::CommentService", protocol="jsonrpc", server="jsonrpc")
 */
class CommentService extends BaseService implements CommentServiceInterface
{
    public function init()
    {
        $this->repository = CommentRepository::getInstance();
    }

    /**
     * Notes: A端 订单评论列表
     * Author: Bruce.z
     * DateTime: 2022/8/19 16:47
     * @param array $condition
     * @param array $field
     * @param int $page
     * @param int $size
     * @return array
     */
    public function index(array $condition, array $field, int $page, int $size): array
    {
        if(!empty($condition['oid']) ){
            $oid = $condition['oid'];
            unset($condition['oid']);
            $condition[] = ['oid','like','%'.trim($oid).'%'];
        }
        return parent::index($condition, $field, $page, $size);
    }

    /**
     * Notes:通过商品评论id获取评价详情
     * Author: Bruce.z
     * DateTime: 2022/10/22 14:46
     * @param int $id
     * @return array
     */
    public function commentDetail(int $id): array
    {
        return $this->repository->commentDetail($id);
    }
}
